<template>
  <div>
    <my-map v-bind:mapInfo="mapInfo"
            @onClickNode="onClickNode"
            @postInitMap="postInitMap"
    />
  </div>
</template>

<script>
  import MyMap from '../MyMap'
  import {shpJsonPage0ZongLan} from './shpJson'
  import {stateManager} from "../StateManager";
  import {Const} from "../Const";
  import {MyMapShpJsonAdapter} from "../MyMapShpJsonAdapter";

  export default {
    name: 'Page0ZongLan',
    components: {
      MyMap: MyMap
    },
    data() {
      return {
        /*************************************
         * Step 1
         * 1）basicMapInfo，MyMap初始化后，获取基础数据，canvas 长，宽，字体
         * 2）mapInfo，地图信息（Model）
         *************************************/
        basicMapInfo: {},
        mapInfo: null,
        myMapShpJsonAdapter: new MyMapShpJsonAdapter()
      }
    },
    methods: {
      onClickNode(node) {
        let data = node.data
        let mxdID = this.myMapShpJsonAdapter.getMxdIDByNodeData(data)
        let dataID = this.myMapShpJsonAdapter.getDataIDFromNodeData(data)
        let pageName = this.myMapShpJsonAdapter.getPageNameByMxdID(mxdID, dataID)
        if (pageName) {
          stateManager.setMxdID(mxdID)
          this.$router.push(pageName)
          // this.$router.push({path: pageName, query: {dataID}})
        }
      },
      /*************************************
       * Step 2 获取绘制地图的基础信息
       *************************************/
      postInitMap(basicMapInfo) {
        this.basicMapInfo = basicMapInfo
      }
    },
    mounted() {
      /*************************************
       * Step 3 转换地图数据
       *************************************/
      let shpJson = shpJsonPage0ZongLan
      let mapInfo = this.myMapShpJsonAdapter.getMapInfo(this.basicMapInfo, shpJson)

      /*************************************
       * Step 4 更新地图数据
       *************************************/
      this.mapInfo = mapInfo
      /*************************************
       * Step 5 周期获取地图信息， 清水池，水泵，阀门
       *************************************/
      let monitorInfo = this.myMapShpJsonAdapter.getMonitorInfoFromMapInfo(mapInfo);
      console.log('monitorInfo:' + JSON.stringify(monitorInfo));
      if (monitorInfo.dataIDList.length > 0) {
        setInterval(async () => {
          let infoList = this.myMapShpJsonAdapter.getInfoListByMonitorInfo(monitorInfo)
          let mapInfo = this.myMapShpJsonAdapter.getMapInfoByInfoList(this.mapInfo, monitorInfo, infoList)
          this.mapInfo = {
            ...mapInfo
          }
        }, 1000)
      }
    }
  }
</script>

<style scoped>
</style>
